package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class JDBCDemo {
    public static void main(String[] args) throws Exception {
        //1.注册驱动
        //Driver类的静态代码块已经进行驱动注册了,我们只需要载入Driver类就会执行,使用反射即可
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取链接
        String url = "jdbc:mysql://localhost:3306/db1?useSSL=false";
        String userName = "root";
        String password = "123456";
        Connection con = DriverManager.getConnection(url,userName,password);
        //定义spl语句
        String sql = "update account set money=2000 where id=1";
        //获取执行语句的对象
        Statement stmt = con.createStatement();
        //执行sql语句,返回值是受影响的行数
        int count = stmt.executeUpdate(sql);
        //处理返回结果
        System.out.println(count);
        //释放资源
        stmt.close();
        con.close();
    }
}
